package com.ityunhe.biz;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;

import com.ityunhe.bean.Garden;
import com.ityunhe.bean.Goods;
import com.ityunhe.bean.Goodsclasses;
import com.ityunhe.bean.Page;
import com.ityunhe.dao.GoodsShowDao;
import com.ityunhe.dao.impl.GoodsShowDaoImpl;

public class GoodsShowBis {
	GoodsShowDao goodsShowDao = new GoodsShowDaoImpl();
	/**
	 * 得到分类信息二级
	 */
	public List<Goodsclasses> getClasses(int depth){
		List<Goodsclasses> list = new ArrayList<Goodsclasses>();
		List<Goodsclasses> listGoodClassDepth = goodsShowDao.listGoodClassDepth(depth);
		return listGoodClassDepth;
		
	}
	/**
	 * 分页查询
	 * @param pa page对象 index size
	 * @param map 查询条件  gaid  gsid
	 * @return
	 */
	public Page  selectPage(Page pa,Map<String, Object> map){
		//Page page = new Page();
	    map.put("pageIndex", (pa.getPageIndex()-1)*pa.getPageSize());
		map.put("pageSize", pa.getPageSize());
		//得到总记录数
		int count = goodsShowDao.countList(map);
		pa.setTotleCount(count);
		
		List<Map> listGoodsPage = goodsShowDao.listGoodsPage(map);
		for (Map map2 : listGoodsPage) {
			String object = (String) map2.get("goodsimages");			
			if(object.indexOf("*")!=-1){
				map2.put("goodsimages",object.substring(0, object.indexOf("*")));
			}else if(object.matches("^[.]+.jsp$")){
				map2.remove("goodsimages");
			}
		}
		pa.setList(listGoodsPage);
		return pa;	
	}

	/**
	 * 得到商家
	 */
	public List<Garden> selectGarden() {
		 List<Garden>  listgarden = new ArrayList<Garden>();
		 listgarden =  goodsShowDao.listGardens();
		return listgarden;
	}

}
